<?php 
class UserController extends Controller{
	public $db;

	public function __init(){
		$this->db=K('User');
	}

	//显示列表
	public function index(){
		$data=$this->db->all();
		$this->assign('data',$data);
		$this->display();
	}

	//添加
	public function add(){
		if(IS_POST){
			if($this->db->addUser()){
				$this->success('用户添加成功','index');
			}else{
				$this->error($this->db->error);
			}
		}else{
			$this->display();
		}
	}

	//编辑
	public function edit(){
		if(IS_POST){
			if($this->db->editUser()){
				$this->success('用户编辑成功','index');
			}else{
				$this->error($this->db->error);
			}
		}else{
			$uid=Q('uid',0,'intval');
			$field=$this->db->find($uid);
			$this->assign('field',$field);
			$this->display();
		}
	}

	//删除
	public function del(){
		if($this->db->delUser()){
			$this->success('用户删除成功','index');
		}else{
			$this->error($this->db->error);
		}
	}

}

?>